package com.advanced.homework0526;

//1:部分质数满足:等于 2的若干次幂-1,比如7(2的三次方-1),31(2的5次方-1),输出1-21亿内所有满足条件的质数.
/**
 * 3、7、31、127、8191、131071、524287、
 * 
 * @author zhaoyang
 *
 */
public class ZhiShu {

	public static void main(String[] args) {
		// 第一种思路

		long a = 2;
		int count = 0;
		for (long i = 2; i < Integer.MAX_VALUE; i++) {
			for (a = 2; i % a != 0 && a * a < i; a++)
				;
			if (a * a > i) {
				// System.out.println(i+ "是质数！");
				for (int j = 2; j - 1 <= i; j *= 2) {
					count++;
					if (j - 1 == i) {
						System.out.println(i + "是质数！是2的" + count + "次方-1！");
					}
				}
			}
		}

		// 第二种思路
		for (long k = 2; k <= Integer.MAX_VALUE; k *= 2) {
			int l = 2;
			for (l = 2; (k - 1) % l != 0 && l * l < (k - 1); l++)
				;
			if (l * l > (k - 1) && k != 2) {
				System.out.println(k - 1);
			}

		}
	}

}
